<!doctype html>
<html class="no-js">

<head>
    <title>幼儿园</title>
    <#include "/boya/template/meta.html" />
</head>

<body>
    <#import "/boya/template/marc.html" as mc />
    <@mc.content>
        <div id="app" class="page">
            <div class="title">食品检验报告 /</div>
            <div class="am-btn-group am-btn-group-sm btn-group">
                <button type="button" class="am-btn am-btn-default" @click="add"><i class="am-icon-plus"></i>&nbsp;新增</button>
            </div>
            <table class="am-table table">
                <thead>
                    <tr>
                        <th>检验时间</th>
                        <th>检验员</th>
                        <th>检验产品</th>
                        <th>检查结果</th>
                        <th>学校</th>
                        <th>下载检验报告</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(item, index) in list">
                        <td class="am-text-middle">{{ item.attrs.date }}</td>
                        <td class="am-text-middle">{{ item.attrs.operator }}</td>
                        <td class="am-text-middle">{{ item.attrs.name }}</td>
                        <td class="am-text-middle">
                            <span v-if="item.attrs.result == 1">合格</span>
                            <span v-if="item.attrs.result == 2">不合格</span>
                        </td>
                        <td class="am-text-middle">{{ item.attrs.schoolName }}</td>
                        <td class="am-text-middle">
                            <a :href="item.attrs.attachment" v-if="item.attrs.attachment">下载</a>
                        </td>
                        <td class="am-text-middle">
                            <button class="am-btn am-btn-default am-btn-xs" @click="edit(item.attrs.id)">编辑</button>
                            <button class="am-btn am-btn-danger am-btn-xs" @click="del(item.attrs.id)"><i class="am-icon-trash"></i>&nbsp;删除</button>
                        </td>
                    </tr>
                </tbody>
            </table>
            <#include "/boya/template/page.html" />
        </div>
    </@mc.content>
    <script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data() {
            return {
                list: []
            }
        },
        mounted: function() {
            var jsonStr = '${list!}';
            if (jsonStr != '') {
                this.list = ${list!}
            }
        },
        methods: {
            add() {
                window.location.href = '/boya/reportInfo';
            },
            edit(id) {
                // layer.open({
                //     type: 2,
                //     area: ['700px', '550px'],
                //     fixed: false, //不固定
                //     maxmin: true,
                //     content: '/boya/reportInfo?id=' + id
                // });
                window.location.href = '/boya/reportInfo?id=' + id;
            },
            del(id) {
                confirm("确认删除？", function() {
                    var param = Qs.stringify({
                        id: id
                    });
                    axios({
                            url: '/boya/delReport',
                            method: 'post',
                            data: param,
                            headers: {
                                'Content-Type': 'application/x-www-form-urlencoded'
                            }
                        })
                        .then(function(response) {
                            if (response.data.status == 200) {
                                // msg("删除成功");
                                window.location.reload();
                            } else {
                                msg("删除失败");
                                console.log(response.data);
                            }
                        })
                        .catch(function(error) {
                            msg("删除失败");
                            console.log(error);
                        });
                })
            },
            onPageChange(val) {
                goPage(val);
            }
        }
    })
    </script>
    <style type="text/css">
    .page {
        padding: 15px;
    }

    .title {
        margin-bottom: 10px;
        font-size: 1.2em;
    }

    .btn-group {
        margin-bottom: 10px;
    }

    .table {
        /*width: auto;*/
    }

    .no-border {
        border: none;
    }
    </style>
</body>

</html>